import React from 'react';
import {HashRouter, Redirect, Route, Switch} from 'react-router-dom';
import Login from '../views/login';
import NewsSandBox from '../views/news_sand_box';

/**
 * 路由组件
 */
function IndexRouter() {
  return (
    <HashRouter>
      <Switch>
        <Route path='/login' component={Login}/>
        {/* <Route path="/" component={NewsSandBox}/> */}
        {/* 判断是否存在token */}
        <Route path='/' render={()=>
          localStorage.getItem('token') ? <NewsSandBox/> : <Redirect to='login'/>
        }/>
      </Switch>
    </HashRouter>
  );
}

export default IndexRouter;